﻿using DevExpress.XtraEditors;
using MixingStation.ConfigSetting;
using MixingStation.LTWebService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace MixingStation
{
    public partial class MixingForm : XtraForm
    {
        private userWs m_CurrentUser = null;
        private bool m_IsOnline = true;

        public MixingForm(userWs currentUser, bool isOnline)
        {
            InitializeComponent();
            m_CurrentUser = currentUser;
            m_IsOnline = isOnline;
            barStaticItemCurrentUser.Caption = m_CurrentUser.employeeName;
        }

        private void MixingForm_Load(object sender, EventArgs e)
        {
            string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            int webServiceTimeSpilt = int.Parse(ConfigurationManager.AppSettings["WebServiceTimeSpilt"]);
            timer.Interval = webServiceTimeSpilt * 1000;
            timer.Enabled = true;
            if (m_IsOnline)
                this.Text = "塔牌混投地秤系统(" + version +  ") 联网";
            else
                this.Text = "塔牌混投地秤系统(" + version + ") 断网";
            Stopwatch sw = new Stopwatch();
            sw.Start();
            //加载初始化数据
            if (!LoadInitData())
            {
                MessageBox.Show("加载初始化数据异常，详见信息请参考日志文件!");
                return;
            }
            sw.Stop();
            LogHelper.info("界面开始加载时初始化基础数据耗时：" + sw.ElapsedMilliseconds);

            int dcUseWay = int.Parse(ConfigurationManager.AppSettings["DCUseWay"]);
            switch (dcUseWay)
            {
                case 0:
                    UseLeftDC();
                    this.Size = new Size(Screen.GetWorkingArea(this).Size.Width / 3 * 2, Screen.GetWorkingArea(this).Size.Height);
                    this.Location = new Point(Screen.GetWorkingArea(this).Size.Width / 6, 0);
                    this.mixingSingleLeft.SetNetWorkStatus(m_IsOnline);
                    break;
                case 1:
                    UseRightDC();
                    this.Size = new Size(Screen.GetWorkingArea(this).Size.Width / 3 * 2, Screen.GetWorkingArea(this).Size.Height);
                    this.Location = new Point(Screen.GetWorkingArea(this).Size.Width / 6, 0);
                    this.mixingSingleRight.SetNetWorkStatus(m_IsOnline);
                    break;
                case 2:
                    UseAllDC();
                    this.Size = Screen.GetWorkingArea(this).Size;
                    this.Location = new Point(0, 0);
                    this.mixingSingleLeft.SetNetWorkStatus(m_IsOnline);
                    this.mixingSingleRight.SetNetWorkStatus(m_IsOnline);
                    break;
            }
        }

        private void UseLeftDC()
        {
            VideoParameter videoParameter = GetVideoParameter(true);
            GateControlParameter gateControlParameter = GetGateControlParameter(true);
            InfraRedParameter infraRedParameter = GetInfraRedParameter(true);
            WeightParameter weightParameter = GetWeightParameter(true);
            OtherParameter otherParameter = GetOtherParameter();
            this.mixingSingleLeft.InitMixingSingleUC(m_CurrentUser, m_MaterialList, m_SupplierList, m_PlaceList, m_DirectionList, m_ReceiveList,
                videoParameter, gateControlParameter, infraRedParameter, weightParameter, otherParameter);
            this.lciRight.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.mixingSingleRight.SetNoUseStatus();
        }

        private void UseRightDC()
        {
            this.lciLeft.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.mixingSingleLeft.SetNoUseStatus();
            VideoParameter videoParameter = GetVideoParameter(false);
            GateControlParameter gateControlParameter = GetGateControlParameter(false);
            InfraRedParameter infraRedParameter = GetInfraRedParameter(false);
            WeightParameter weightParameter = GetWeightParameter(false);
            OtherParameter otherParameter = GetOtherParameter();
            this.mixingSingleRight.InitMixingSingleUC(m_CurrentUser, m_MaterialList, m_SupplierList, m_PlaceList, m_DirectionList,m_ReceiveList,
                videoParameter, gateControlParameter, infraRedParameter, weightParameter, otherParameter);
        }

        private void UseAllDC()
        {
            VideoParameter videoParameter = GetVideoParameter(true);
            GateControlParameter gateControlParameter = GetGateControlParameter(true);
            InfraRedParameter infraRedParameter = GetInfraRedParameter(true);
            WeightParameter weightParameter = GetWeightParameter(true);
            OtherParameter otherParameter = GetOtherParameter();
            this.mixingSingleLeft.InitMixingSingleUC(m_CurrentUser, m_MaterialList, m_SupplierList, m_PlaceList, m_DirectionList,m_ReceiveList, 
                videoParameter, gateControlParameter, infraRedParameter, weightParameter, otherParameter);

            videoParameter = GetVideoParameter(false);
            gateControlParameter = GetGateControlParameter(false);
            infraRedParameter = GetInfraRedParameter(false);
            weightParameter = GetWeightParameter(false);
            this.mixingSingleRight.InitMixingSingleUC(m_CurrentUser, m_MaterialList, m_SupplierList, m_PlaceList, m_DirectionList,m_ReceiveList,
               videoParameter, gateControlParameter, infraRedParameter, weightParameter, otherParameter);
        }
        private VideoParameter GetVideoParameter(bool isLeft)
        {
            VideoParameter videoParameter = new VideoParameter();
            videoParameter.IsShowVideo = int.Parse(ConfigurationManager.AppSettings["IsShowVideo"]) == 1 ? true : false;
            videoParameter.VideoType = int.Parse(ConfigurationManager.AppSettings["VideoType"]);
            videoParameter.IsCapture = int.Parse(ConfigurationManager.AppSettings["IsCapture"]) == 1 ? true : false;
            videoParameter.CapturePath = ConfigurationManager.AppSettings["CapturePath"].ToString();

            if (isLeft)
            {
                videoParameter.VideoIP = ConfigurationManager.AppSettings["LeftVideoIP"].ToString();
                videoParameter.VideoPort = int.Parse(ConfigurationManager.AppSettings["LeftVideoPort"]);
                videoParameter.VideoUser = ConfigurationManager.AppSettings["LeftVideoUser"].ToString();
                videoParameter.VideoPassword = ConfigurationManager.AppSettings["LeftVideoPassword"].ToString();
                videoParameter.VideoChannel = short.Parse(ConfigurationManager.AppSettings["LeftVideoChannel"]);
            }
            else
            {
                videoParameter.VideoIP = ConfigurationManager.AppSettings["RightVideoIP"].ToString();
                videoParameter.VideoPort = int.Parse(ConfigurationManager.AppSettings["RightVideoPort"]);
                videoParameter.VideoUser = ConfigurationManager.AppSettings["RightVideoUser"].ToString();
                videoParameter.VideoPassword = ConfigurationManager.AppSettings["RightVideoPassword"].ToString();
                videoParameter.VideoChannel = short.Parse(ConfigurationManager.AppSettings["RightVideoChannel"]);
            }
            return videoParameter;
        }

        private GateControlParameter GetGateControlParameter(bool isLeft)
        {
            GateControlParameter gateControlParameter = new GateControlParameter();
            gateControlParameter.GateWay = int.Parse(ConfigurationManager.AppSettings["GateWay"]);
            gateControlParameter.GateControlWay = int.Parse(ConfigurationManager.AppSettings["GateControlWay"]);
            if (isLeft)
            {
                gateControlParameter.IpOfGateIO = ConfigurationManager.AppSettings["IpOfLeftGateIO"].ToString();
                gateControlParameter.FGateUp = int.Parse(ConfigurationManager.AppSettings["LeftFGateUp"]);
                gateControlParameter.FGateDown = int.Parse(ConfigurationManager.AppSettings["LeftFGateDown"]);
                gateControlParameter.BGateUp = int.Parse(ConfigurationManager.AppSettings["LeftBGateUp"]);
                gateControlParameter.BGateDown = int.Parse(ConfigurationManager.AppSettings["LeftBGateDown"]);
            }
            else
            {
                gateControlParameter.IpOfGateIO = ConfigurationManager.AppSettings["IpOfRightGateIO"].ToString();
                gateControlParameter.FGateUp = int.Parse(ConfigurationManager.AppSettings["RightFGateUp"]);
                gateControlParameter.FGateDown = int.Parse(ConfigurationManager.AppSettings["RightFGateDown"]);
                gateControlParameter.BGateUp = int.Parse(ConfigurationManager.AppSettings["RightBGateUp"]);
                gateControlParameter.BGateDown = int.Parse(ConfigurationManager.AppSettings["RightBGateDown"]);
            }
            return gateControlParameter;
        }

        private InfraRedParameter GetInfraRedParameter(bool isLeft)
        {
            InfraRedParameter parameter = new InfraRedParameter();
            parameter.InfraRedWay = int.Parse(ConfigurationManager.AppSettings["InfraredWay"]);
            parameter.IsTurnover = int.Parse(ConfigurationManager.AppSettings["IsTurnover"]);
            if (isLeft)
            {
                parameter.IPAddrOfInfraIO = ConfigurationManager.AppSettings["IpOfLeftInfraredIO"].ToString();
                parameter.FInfrared = int.Parse(ConfigurationManager.AppSettings["LeftFInfrared"]);
                parameter.BInfrared = int.Parse(ConfigurationManager.AppSettings["LeftBInfrared"]);
            }
            else
            {
                parameter.IPAddrOfInfraIO = ConfigurationManager.AppSettings["IpOfRightInfraredIO"].ToString();
                parameter.FInfrared = int.Parse(ConfigurationManager.AppSettings["RightFInfrared"]);
                parameter.BInfrared = int.Parse(ConfigurationManager.AppSettings["RightBInfrared"]);
            }
            return parameter;
        }

        private WeightParameter GetWeightParameter(bool isLeft)
        {
            WeightParameter parameter = new WeightParameter();
            if (isLeft)
            {
                parameter.DCType = int.Parse(ConfigurationManager.AppSettings["LeftDCType"]);
                parameter.DCName = ConfigurationManager.AppSettings["LeftDCName"].ToString();
                parameter.DCCom = ConfigurationManager.AppSettings["LeftDCCom"].ToString();
                parameter.DCPort = int.Parse(ConfigurationManager.AppSettings["LeftDCBaud"]);
                parameter.CompareTimes = int.Parse(ConfigurationManager.AppSettings["LeftCompareTimes"]);
            }
            else
            {
                parameter.DCType = int.Parse(ConfigurationManager.AppSettings["RightDCType"]);
                parameter.DCName = ConfigurationManager.AppSettings["RightDCName"].ToString();
                parameter.DCCom = ConfigurationManager.AppSettings["RightDCCom"].ToString();
                parameter.DCPort = int.Parse(ConfigurationManager.AppSettings["RightDCBaud"]);
                parameter.CompareTimes = int.Parse(ConfigurationManager.AppSettings["RightCompareTimes"]);
            }
            return parameter;
        }

        private OtherParameter GetOtherParameter()
        {
            OtherParameter parameter = new OtherParameter();
            parameter.BelongCorpId = int.Parse(ConfigurationManager.AppSettings["BelongCorpId"]);
            parameter.CorpName = ConfigurationManager.AppSettings["CorpName"].ToString();
            parameter.IsNeedZero = int.Parse(ConfigurationManager.AppSettings["IsNeedZero"]) == 1 ? true : false;
            parameter.BackOverWeight = int.Parse(ConfigurationManager.AppSettings["BackOverWeight"]);
            string deliveryCodeStr = ConfigurationManager.AppSettings["DeliveryCode"].ToString();
            //parameter.DistanceX = decimal.Parse(ConfigurationManager.AppSettings["DistanceX"]);
            //parameter.DistanceY = decimal.Parse(ConfigurationManager.AppSettings["DistanceY"]);
            foreach (string code in deliveryCodeStr.Split(','))
            {
                if (!parameter.DeliveryCodeList.Contains(code))
                    parameter.DeliveryCodeList.Add(code);
            }
            if (m_IsOnline)
            {
                using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
                {
                    cardParameterSetWS ws = client.getCardParameterSet(2);
                    parameter.DeliveryWeightValue = ws.parameter7;
                    parameter.GrossWeightValue = ws.parameter8;
                    parameter.CarWeightValue = ws.parameter9;
                }
            }
            return parameter;
        }

        #region 初始化数据
        private List<materialWS> m_MaterialList = new List<materialWS>();
        private List<supplierWS> m_SupplierList = new List<supplierWS>();
        private List<placeWS> m_PlaceList = new List<placeWS>();
        private List<DirectionInfo> m_DirectionList = new List<DirectionInfo>();
        private List<ReceiveInfo> m_ReceiveList = new List<ReceiveInfo>();
        //加载初始化数据
        private bool LoadInitData()
        {
            try
            {
                using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
                {
                    if (!(LoadMaterialInfo(client) && LoadSupplierInfo(client) && LoadPlaceInfo(client)
                        && LoadDirectionInfo() && LoadReceiveInfo()))
                        return false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化数据异常：" + ex.ToString());
                return false;
            }
            return true;
        }

        //加载化物料
        private bool LoadMaterialInfo(LTCardAPIServiceClient client)
        {
            try
            {
                string sqlStr = "";
                if (m_IsOnline)
                {
                    materialWS[] materialArr = client.getPurMaterial(0, "", "", "");
                    if (materialArr != null && materialArr.Length > 0)
                        m_MaterialList.AddRange(materialArr);
                    sqlStr = "select * from Material where IsSystem = false order by Code";
                }
                else
                {
                    sqlStr = "select * from Material order by Code";
                }
                DataTable materialDT = CommonHelper.DoSelectOpreation(sqlStr);
                if (materialDT != null && materialDT.Rows.Count > 0)
                {
                    foreach (DataRow dr in materialDT.Rows)
                    {
                        string code = dr["Code"].ToString();
                        string material = dr["Name"].ToString();
                        decimal buckleRate = decimal.Parse(dr["DefaultBuckleRate"].ToString());
                        m_MaterialList.Add(CommonHelper.CreateMaterialWS(code, material, buckleRate));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("获取物料数据异常：" + ex.ToString());
                return false;
            }
            return true;
        }

        //加载供应商
        private bool LoadSupplierInfo(LTCardAPIServiceClient client)
        {
            try
            {
                string sqlStr = "";
                if (m_IsOnline)
                {
                    supplierWS[] supplierArr = client.getSupplier(0, "", "");
                    if (supplierArr != null && supplierArr.Length > 0)
                        m_SupplierList.AddRange(supplierArr);
                    sqlStr = "select * from Supplier where IsSystem = false order by Code";
                }
                else
                {
                    sqlStr = "select * from Supplier order by Code";
                }
                DataTable supplierDT = CommonHelper.DoSelectOpreation(sqlStr);
                if (supplierDT != null && supplierDT.Rows.Count > 0)
                {
                    foreach (DataRow dr in supplierDT.Rows)
                    {
                        string code = dr["Code"].ToString();
                        string supplier = dr["Name"].ToString();
                        m_SupplierList.Add(CommonHelper.CreateSupplierWS(code, supplier));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("加载供应商数据异常：" + ex.Message);
                return false;
            }
            return true;
        }

        //加载产地信息
        private bool LoadPlaceInfo(LTCardAPIServiceClient client)
        {
            try
            {
                string sqlStr = "";
                if (m_IsOnline)
                {
                    placeWS[] placeArr = client.getPlaces(0, "", "");
                    if (placeArr != null && placeArr.Length > 0)
                        m_PlaceList.AddRange(placeArr);
                    sqlStr = "select * from Place where IsSystem = false order by Code";
                }
                else
                {
                    sqlStr = "select * from Place order by Code";
                }
                DataTable placeDT = CommonHelper.DoSelectOpreation(sqlStr);
                if (placeDT != null && placeDT.Rows.Count > 0)
                {
                    foreach (DataRow dr in placeDT.Rows)
                    {
                        string code = dr["Code"].ToString();
                        string place = dr["Name"].ToString();
                        m_PlaceList.Add(CommonHelper.CreatePlaceWS(code, place));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("加载产地数据异常：" + ex.Message);
                return false;
            }
            return true;
        }

        //加载流向
        private bool LoadDirectionInfo()
        {
            try
            {
                string sqlStr = "select * from Direction order by Code";
                DataTable directionDT = CommonHelper.DoSelectOpreation(sqlStr);
                if (directionDT != null && directionDT.Rows.Count > 0)
                {
                    m_DirectionList = new List<DirectionInfo>();
                    foreach (DataRow dr in directionDT.Rows)
                    {
                        string code = dr["Code"].ToString();
                        string place = dr["Name"].ToString();
                        bool isDefault = dr["IsDefault"].ToString().ToUpper() == "TRUE" ? true : false;
                        m_DirectionList.Add(CommonHelper.CreateDirectionInfo(code, place, isDefault));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("加载流向数据异常：" + ex.Message);
                return false;
            }
            return true;
        }
        //加载收货单位
        private bool LoadReceiveInfo()
        {
            try
            {
                string sqlStr = "select * from Receive order by Code";
                DataTable receiveDT = CommonHelper.DoSelectOpreation(sqlStr);
                if (receiveDT != null && receiveDT.Rows.Count > 0)
                {
                    m_ReceiveList = new List<ReceiveInfo>();
                    foreach (DataRow dr in receiveDT.Rows)
                    {
                        string code = dr["Code"].ToString();
                        string receive = dr["Name"].ToString();
                        m_ReceiveList.Add(CommonHelper.CreateReceiveInfo(code, receive));
                    }
                }
            }
            catch (Exception ex) 
            {
                LogHelper.error("加载流向数据异常：" + ex.Message);
                return false;
            }
            return true;
        }
        #endregion

        //监控是否联网
        private void timer_Tick(object sender, EventArgs e)
        {
            //using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
            //{
            //    m_IsOnline = ServerCommonHelper.IsWebServiceAvaiable(client.Endpoint.Address.Uri);
            //}
            Thread thread = new Thread(NetworkCheck);
            thread.Start();
        }


        private void NetworkCheck()
        {
            try
            {
                using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
                {
                    m_IsOnline = ServerCommonHelper.IsWebServiceAvaiable(client.Endpoint.Address.Uri);
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("网络检查异常：" + ex.Message);
                return;
            }
            Invoke(new myNetworkDelegate(RefreshNetworkInfo));
        }

        private delegate void myNetworkDelegate();
        private void RefreshNetworkInfo()
        {
            if (lciLeft.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
                this.mixingSingleLeft.SetNetWorkStatus(m_IsOnline);
            if (lciRight.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
                this.mixingSingleRight.SetNetWorkStatus(m_IsOnline);
            string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            if (m_IsOnline)
                this.Text = "塔牌混投地秤系统(" + version + ") 联网";
            else
                this.Text = "塔牌混投地秤系统(" + version + ") 断网";
        }
        
        private void barButtonItemDCCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WeightSetForm form = new WeightSetForm();
            form.ShowDialog();
        }

        private void barButtonItemVideoCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            VideoSetForm form = new VideoSetForm();
            form.ShowDialog();
        }

        private void barButtonItemInfraredCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            InfraredSetForm form = new InfraredSetForm();
            form.ShowDialog();
        }

        private void barButtonItemGateCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            GateSetForm form = new GateSetForm();
            form.ShowDialog();
        }

        private void barButtonItemPasswordCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            AccessFilePassSet set = new AccessFilePassSet();
            set.ShowDialog();
        }

        private void barButtonItemDBCfg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DBCfgForm form = new DBCfgForm();
            form.ShowDialog();
        }
        private void barButtonItemMaterial_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalMateialCfgForm form = new LocalMateialCfgForm();
            form.ShowDialog();
        }

        private void barButtonItemSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalSupplierCfgForm form = new LocalSupplierCfgForm();
            form.ShowDialog();
        }

        private void barButtonItemPlace_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalPlaceCfgForm form = new LocalPlaceCfgForm();
            form.ShowDialog();
        }

        private void barButtonItemDirection_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalDirectionCfgForm frm = new LocalDirectionCfgForm();
            frm.ShowDialog();
        }

        private void barButtonItemUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalUserCfgForm frm = new LocalUserCfgForm();
            frm.ShowDialog();
        }

        private void barButtonItemReceive_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalReceiveCfgForm form = new LocalReceiveCfgForm();
            form.ShowDialog();
        }

        private void barButtonItemPurchase_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WeightInfoForm form = new WeightInfoForm();
            form.MaterialList = m_MaterialList;
            form.SupplierList = m_SupplierList;
            form.PlaceList = m_PlaceList;
            form.DirectionList = m_DirectionList;
            form.ShowDialog();
        }

        private void barButtonItemUnPurchase_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UnPurchaseWeightInfoForm form = new UnPurchaseWeightInfoForm();
            form.MaterialList = m_MaterialList;
            form.SupplierList = m_SupplierList;
            form.PlaceList = m_PlaceList;
            form.DirectionList = m_DirectionList;
            form.CurrentUser = m_CurrentUser.userame;
            form.Password = m_CurrentUser.password;
            form.ShowDialog();
        }

        private void barButtonItemLocal_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LocalWeightInfoForm form = new LocalWeightInfoForm();
            form.MaterialList = m_MaterialList;
            form.SupplierList = m_SupplierList;
            form.PlaceList = m_PlaceList;
            form.DirectionList = m_DirectionList;
            form.ShowDialog();
        }

        private void barButtonItemChangeUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show("切换用户过程中,请停止操作,是否确认切换?", "提示",
             MessageBoxButtons.OKCancel) != DialogResult.OK)
                return;
            FormLogin frmlogin = new FormLogin();
            if (frmlogin.ShowDialog() == DialogResult.OK)
            {
                barStaticItemCurrentUser.Caption = frmlogin.CurrentUser.employeeName;
            }
        }

        private void MixingForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否确认关闭", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                e.Cancel = true;
            }
        }

        private void MixingForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
            if (System.Diagnostics.Process.GetCurrentProcess() != null)
                System.Diagnostics.Process.GetCurrentProcess().Kill(); 
        }
    }
}
